package ie.dit.reg08.realiser;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;

public class AttributeValueWordCount {

	private String value;
	private HashMap<String, Integer> wordCounts;
	
	public AttributeValueWordCount(String val){
		value = val;
		wordCounts = new HashMap<String, Integer>();
	}
	
	public boolean hasWord(String word){
		return wordCounts.containsKey(word);
	}
	
	public void addWord(String word){
		wordCounts.put(word, 0);
	}
	
	public void incrementWordCount(String word){
		// Check to see if the word is already on the list and if not put it on
		if(!hasWord(word)){
			addWord(word);
		}
		wordCounts.put(word, wordCounts.get(word) + 1);
	}
	
	public String toString(){
		
		StringBuffer s = new StringBuffer("");
			
	    Set<String> ks = wordCounts.keySet();
		Iterator<String> iterKey = ks.iterator();
		String sKey;
		while(iterKey.hasNext()) {
			sKey = iterKey.next();
			s.append(sKey);
			s.append("[");
	    	Integer wordCount = wordCounts.get(sKey);
	    	s.append(wordCount.toString());
	    	s.append("] ");
		}
		
	    return s.toString();
	}
}
